package com.xgp.weixinxgp.tool;

import com.xgp.weixinxgp.model.*;
import net.sf.json.JSONObject;
@SuppressWarnings("all")
public class CreateMenu {

    public static void main(String arg[]) {
        //菜单对象
        Button btn = new Button();
//        btn.getButton().add(new AbstractButon("菜单一"));
//        btn.getButton().add(new AbstractButon("菜单二"));
        //第一个一级菜单
        btn.getButton().add(new ClickButton("一级点击","1"));
        btn.getButton().add(new ViewButton("一级跳转","http://www.baidu.com"));
        //创建第三个一级菜单
        SubButton sb = new SubButton("有子菜单");
        //为第三个一级菜单增加了子菜单
        sb.getSub_button().add(new PhotoOrAlbumButton("传图","31"));
        sb.getSub_button().add(new ClickButton("点击","32"));
        sb.getSub_button().add(new ViewButton("去qq","http://www.qq.com"));

        btn.getButton().add(sb);
        JSONObject jsonStr = JSONObject.fromObject(btn);
//        System.out.println(jsonStr.toString());

        String url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";
        url = url.replace("ACCESS_TOKEN",WxTool.getAccessToken());
        //发送请求
        String result = WxTool.post(url, jsonStr.toString());
        System.out.println(result);
    }
}
